<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<div th:fragment="track">

    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script type="text/javascript">
        var tip = ''
        try {
            tip = returnCitySN["cip"]
        } catch (error) {
            tip = ''
        }
        /**
         * 埋点工具
         * @param staffId 职工id
         * @param pageName 页面名称
         * @param sysPackage 业务参数 json对象
         */

        function webTrackingUtil(elementName, pageUrl, eventType, eventId, sysPackage) {
            let url = '';
            let env = '[[${ZMN_URL_ENV}]]'
            if (env === 'http://dev-') {
                // 开发环境
                url = 'https://zmn-ls-dev.cn-beijing.log.aliyuncs.com/logstores/user_event_tracking_log/track'
            } else if (env === 'http://test2-') {
                // 测试环境
                url = 'https://zmn-ls-test2.cn-beijing.log.aliyuncs.com/logstores/user_event_tracking_log/track'
            } else if (env === 'http://pre-') {
                // 预生产
                url = 'https://zmn-ls-pre.cn-beijing.log.aliyuncs.com/logstores/user_event_tracking_log/track'
            } else {
                // 生产
                url = 'https://zmn-user-behavior.cn-beijing.log.aliyuncs.com/logstores/user_event_tracking_log/track'
            }
            var settings = {
                "url": url,
                "method": "POST",
                "timeout": 0,
                "headers": {
                    "x-log-apiversion": "0.6.0",
                    "x-log-bodyrawsize": "1234",
                    "Content-Type": "application/json"
                },
                "data": JSON.stringify({
                    "__logs__": [{
                            event_time: getDate(), // 事件时间
                            browser_name: '', // 浏览器型号
                            browser_version: '', // 浏览器版本
                            os: getOS(), // 操作系统
                            os_version: getOsVersion(getOS()), // 操作系统版本
                            app: 'zmn_sys', // 站点唯一标识
                            ip: tip, // ip地址
                            userId: '[[${staffId}]]', // 用户id
                            imei: '', // 设备imei
                            network: getNetworkType(), // 设备网络
                            platform: 'web', // 平台
                            device_type: 'pc', // 设备类型
                            utm_source: '', // 流量来源
                            longitude: '', // 经度
                            latitude: '', // 纬度
                            event_type: eventType, // 事件类型
                            event_id: eventId, //事件id
                            page_url: location.href, // 页面url
                            page_name: 'SYS_ADMIN', // 页面名称
                            duration: '', // 页面停留时间
                            page_package: '', // 页面参数集
                            element_package: '', // 元素参数集
                            element_name: elementName,
                            business_package: JSON.stringify({
                                sys_package: sysPackage
                            })


                        },

                    ]

                }),
            };


            $.ajax(settings).done(function(response) {});
        }

        /**
         * @param _this 点击的链接
         * 获取面包屑
         **/
        function getMenu(_this) {
            console.log(_this)
            let firstMenu = _this.parent('dd').parent('dl').prev('a').text();
            firstMenu = firstMenu === '' ? '' : "/" + firstMenu
            let secondMenu = _this.parent('dd').parent('dl').prev('a').parent('dd').parent('dl').prev('a').text();
            secondMenu = secondMenu === '' ? '' : "/" + secondMenu
            let ThirdMenu = _this.parent('dd').parent('dl').prev('a').parent('dd').parent('dl').prev('a').parent('dd').parent('dl').prev('a').text();
            ThirdMenu = ThirdMenu === '' ? '' : "/" + ThirdMenu
            return ('报表中心' + ThirdMenu + secondMenu + firstMenu + "/" + _this.text()).replace(/\s*/g, "");
        }





        /**
         * 获取操作系统
         * @returns {string}
         */
        function getOS() {
            var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
            if (isWin) return 'windows';
            var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
            if (isMac) return "Mac";
            var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
            if (isUnix) return "Unix";
            var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
            if (isLinux) return "Linux";
            return "other";
        }

        /**
         * 获取当前时间
         * @returns {string}
         */
        function getDate() {
            var datetime = new Date();
            var year = datetime.getFullYear();
            var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
            var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
            let hh = datetime.getHours()
            let mf = datetime.getMinutes() < 10 ? '0' + datetime.getMinutes() : datetime.getMinutes()
            let ss = datetime.getSeconds() < 10 ? '0' + datetime.getSeconds() : datetime.getSeconds()
            let ms = datetime.getMilliseconds();
            if (ms < 10) {
                ms = "00" + ms;
            } else if (ms < 100) {
                ms = '0' + ms;
            }
            return year + '-' + month + '-' + date + ' ' + hh + ':' + mf + ':' + ss + " " + ms;
        }

        /**
         * 获取操作系统版本
         * @param os 操作系统
         * @returns {string}
         */
        function getOsVersion(os) {
            var sUserAgent = navigator.userAgent;
            var isWin = os === 'windows';
            if (isWin) {
                var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;
                if (isWin2K) return "Win2000";
                var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;
                if (isWinXP) return "WinXP";
                var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;
                if (isWin2003) return "Win2003";
                var isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
                if (isWinVista) return "WinVista";
                var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
                if (isWin7) return "Win7";
                var isWin10 = sUserAgent.indexOf("Windows NT 10") > -1 || sUserAgent.indexOf("Windows 10") > -1;
                if (isWin10) return "Win10";
            } else {
                var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
                if (isMac) return navigator.platform.replace('Mac', '');
                var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
                if (isUnix) return "Unix";
                var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
                if (isLinux) return "Linux";
            }
            return 'other';
        }

        /**
         * 设备网络
         * @returns {string}
         */
        function getNetworkType() {
            var ua = navigator.userAgent;
            var networkStr = ua.match(/NetType\/\w+/) ? ua.match(/NetType\/\w+/)[0] : 'NetType/other';
            networkStr = networkStr.toLowerCase().replace('nettype/', '');
            var networkType;
            switch (networkStr) {
                case 'wifi':
                    networkType = 'wifi';
                    break;
                case '4g':
                    networkType = '4g';
                    break;
                case '3g':
                    networkType = '3g';
                    break;
                case '3gnet':
                    networkType = '3g';
                    break;
                case '2g':
                    networkType = '2g';
                    break;
                default:
                    networkType = 'other';
            }
            return networkType;
        }
    </script>
</div>